import React, { Component } from 'react'
import { Modal, Button, Input } from 'antd';
import { connect } from 'umi'

class CreateUser extends Component {
    state = {
        name: '',
        department: '',
        hiredate: '',
        level: ''
    }

    handleOk = () => {
        const { hideModal, dispatch } = this.props
        hideModal()
        dispatch({
            type: 'user/add',
            payload: {
                ...this.state
            }
        })
    }
    handleCancel = () => {
        this.props.hideModal()
    }

    changeState = (key, v) => {
        this.setState({
            [key]: v
        })
    }

    render() {

        const { name, department, hiredate, level } = this.state

        const { isShow } = this.props
        return (
            <div>
                <Modal
                    title="添加员工"
                    visible={isShow}
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                >
                <p>姓名: <Input 
                            value={name} 
                            onChange={v => this.changeState('name', v.currentTarget.value)} 
                        />
                </p>
                <p>部门:
                        <Input 
                            value={department} 
                            onChange={v => this.changeState('department', v.currentTarget.value)} 
                        />
                     </p>
                <p>入职时间: 
                        <Input 
                            value={hiredate} 
                            onChange={v => this.changeState('hiredate', v.currentTarget.value)} 
                        />

                </p>
                <p>职级: 
                        <Input 
                            value={level} 
                            onChange={v => this.changeState('level', v.currentTarget.value)} 
                        />
                </p>
                </Modal>
            </div>
        )
    }
}


export default connect()(CreateUser)